package cn.lntu.d1018;



import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;


/**
 * A simple {@link Fragment} subclass.
 */
public class Fragment3 extends Fragment {


    private MainActivity activity;

    public Fragment3() {

    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity =(MainActivity) getActivity();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_fragment3, container,false);
        //找到Listview
        ListView lvMain=view.findViewById(R.id.lv_main3);
        //创建适配器
        MyAdapter adapter=new MyAdapter();
        //位Listview添加适配器
        lvMain.setAdapter(adapter);

        return view;
    }

    private class MyAdapter extends BaseAdapter {
        @Override
        public int getCount() {

            return 10;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView==null){
                convertView=View.inflate(activity.getApplicationContext(),R.layout.item3,null);
            }
            TextView tvTitle=convertView.findViewById(R.id.tv_title);
            tvTitle.setText("第"+position+"行");

            return convertView;
        }
    }
}